#include "iodefine.h"
#include "compler.h"
#include "gpt.h"
#include "iirfilter.h"
#include "ad12.h"
#include "pcinterface.h"
#pragma interrupt (CMT0_CM0(vect=VECT(CMT0,CMI0)))

#pragma interrupt (SCI2_TXI2(vect=VECT(SCI2,TXI2)))
#pragma interrupt (SCI2_RXI2(vect=VECT(SCI2,RXI2)))
#pragma interrupt (SCI2_ERI2(vect=VECT(SCI2,ERI2)))
#pragma interrupt (SCI2_TEI2(vect=VECT(SCI2,TEI2)))
#pragma interrupt (ad0_pro(vect=VECT(S12AD0,S12ADI0)))
#pragma interrupt (ad1_pro(vect=VECT(S12AD1,S12ADI1)))
#pragma interrupt (cmp_pro(vect=VECT(S12AD,CMPI)))

#pragma interrupt (adi0_pro(vect=VECT(AD0,ADI0)))


unsigned int addr0;
unsigned int addr1;
unsigned int addr2;
unsigned int addr3;




 


void cmp_pro(void)
{
	unsigned char a;
	led_on_v1(4);
	vc_err_pro();
	if(is_cmp_10_out())
	{
		a=0;
	}
	if(is_cmp_11_out())
	{
		a=0;
	}
	if(is_cmp_12_out())
	{
		a=0;
	}
	
}
;


//#include "iirfilter.c"
extern void uart2_dat_err_intp(void);
// SCI2_ERI2
void SCI2_ERI2(void)
{
	uart2_dat_err_intp();
}
;
extern void uart2_dat_rece_intp(void);
// SCI2_RXI2
void SCI2_RXI2(void)
{
	uart2_dat_rece_intp();
}
;
extern void uart2_dat_send_intp(void);

// SCI2_TXI2
void SCI2_TXI2(void)
{
	uart2_dat_send_intp();
}
;

// SCI2_TEI2
void SCI2_TEI2(void)
{
}
;

extern  void key_input_init(void);
extern void systemp_2ms_pro(void);
void CMT0_CM0(void)
{
	key_input_init();
	systemp_2ms_pro();
}
;
//extern pfc_run
void ad0_pro(void)
{
	pfc_run();
}


void ad1_pro(void)
{
	//unsigned int addr0;
//	unsigned int addr1;
//	unsigned int addr2;
//	unsigned int addr3;
    unsigned int datacycle;
	addr0 = S12AD1.ADDR0A;
//	addr1 = S12AD1.ADDR1;
//	addr2 = S12AD1.ADDR2;
//	addr3 = S12AD1.ADDR3;

	Cycle_data = DCDC_PID_GetValue(addr0);

	if(Cycle_data < 300) 
    {
        Cycle_data = 300;
    }
 
    if(Cycle_data > 1250)
    {
        Cycle_data = 1250;
    }
	
	if(GPT_run == GPT_START)
	{
		enable_wgpt2();
		enable_wgpt3();
		if(FRE_DUTY_run == FRE_START)
		{
			//Cycle_data-=10;
			//if(Cycle_data < 300)
			//{
			//	Cycle_data = 300;
			//}				
			GPT3.GTST.BIT.TCFPO = 0;	
			while(!GPT3.GTST.BIT.TCFPO)
			{
				;
			}
				GPT3.GTST.BIT.TCFPO = 0;

				GPT2.GTPBR = Cycle_data;
				GPT3.GTPBR = Cycle_data;				
				GPT3.GTCCRC = Cycle_data/2;
				GPT2.GTCCRC = Cycle_data/2;

		 }
	}

}

void adi0_pro(void)
{
	unsigned int addra;
	unsigned int addrb;
	unsigned int addrc;
	unsigned int addrd;
	addra = AD0.ADDRA;
	addrb = AD0.ADDRB;
	addrc = AD0.ADDRC;
	addrd = AD0.ADDRD;
}
